import BaseTable from '../BaseTable/BaseTable.vue';
export default {
    name: 'BudgetList',
    props: ['data'],
    components: {
        BaseTable
    },
    data() {
        return {
            tableConfig: [
                { prop: 'projectNumber', label: '项目编号', width: '100' },
                { prop: 'projectName', label: '项目名称', width: '100', showTips: true },
                { prop: 'featureDescription', label: '特征描述', width: '100', showTips: true },
                { prop: 'unit', label: '单位', width: '100' },
                {
                    prop: 'covertItem',
                    label: '是否隐藏项',
                    width: '100',
                    formatter(val) {
                        const coverItemMap = { 0: '否', 1: '是' };
                        return coverItemMap[val];
                    }
                },
                {
                    prop: 'quantities',
                    label: '工程量',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'integratedUnitPrice',
                    label: '综合单价',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'totalPrice',
                    label: '综合总价',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'materialsBrand',
                    label: '主材品牌',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'declareQuantities',
                    label: '申报工作量',
                    type: 'input',
                    change: null
                },
                {
                    prop: 'declareTotalPrice',
                    label: '申报综合总价',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'declareMaterialsBrand',
                    label: '申报主材品牌',
                    type: 'select',
                    width: '100'
                },
                { prop: 'brandExplain', label: '品牌说明', type: 'input' },
                {
                    prop: 'examineQuantities',
                    label: '审核工作量',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'examineTotalPrice',
                    label: '审核综合总价',
                    disabled: true,
                    type: 'input',
                    width: '100'
                },
                {
                    prop: 'examineMaterialsBrand',
                    label: '审核主材品牌',
                    type: 'select',
                    width: '100'
                }
            ]
        };
    },
    computed: {
        tableData() {
            const list = this.data.templateList;
            list &&
                list.forEach(v => {
                    v.options = v.materialsBrand?.split(',');
                });
            return this.data.templateList;
        }
    },
    mounted() {
        this.initQuantityReact();
    },
    methods: {
        // 为工程量、综合单价输入框注册input事件
        initQuantityReact() {
            const vm = this;
            let col = vm.tableConfig.find(v => v.prop === 'declareQuantities');
            col.change = (val, { row, $index }) => {
                const ret = (+row.integratedUnitPrice || 0).mul(+val).toFixed(2);
                vm.data.templateList[$index].declareTotalPrice = ret;
                vm.$root.$emit('calcTaxRate');
            };
        }
    }
};
